home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / pj9_3.arc / STRNCPY.ASM < prev    next >
Assembly Source File  |  1991-10-07  |  596b  |  36 lines

  1.     title    strncpy
  2.     include    asm.inc
  3.  
  4.     public    strncpy
  5.  
  6.     .code
  7.  
  8. ;;    strncpy
  9. ;
  10. ;    entry    DS:SI    source string
  11. ;        ES:DI    destination buffer
  12. ;        CX    byte count (includes room for \0)
  13. ;    exit    SI    updated (past \0 unless CX too small)
  14. ;        DI    updated (points to \0)
  15. ;        CX    updated
  16. ;    uses    AX
  17. ;
  18. strncpy proc
  19.     jcxz    snc3            ; if no space in destination
  20.  
  21. snc1:    lodsb                ; copy string
  22.     stosb
  23.     cmp    al,NULL_CHAR
  24.     loopne    snc1
  25.     je    snc2            ;  if end of source string
  26.  
  27.     dec    di            ;  else backup destination and
  28.     mov    al,NULL_CHAR        ;   delimit string
  29.     stosb
  30.  
  31. snc2:    dec    di
  32. snc3:    ret
  33. strncpy endp
  34.  
  35.     end
  36.